// pages/searchgoods/searchgoods.js
var app = getApp()
const $api = require('../../utils/api.js').API;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 组件所需的参数
    navbarData: {
      havebg: 1, //1表示显示    0表示不显示
      out: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '搜索结果', //导航栏 中间的标题
      bg: '#fff', //导航背景
    },
    height: app.globalData.height,
    sousuoType:'',//home 从首页进变搜索  search 搜索结果商品列表
    rmlist:['养生','养生','面膜','氨基酸','健康养生','牙刷','牙膏','毛巾',],
    search:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options)
    let _this = this
    _this.setData({
      sousuoType: options.sousuoType,
      search: options.search,
    })
    
  },
  out() {
    wx.navigateBack({
      delta: 1,
    })
  },
  getptGoods(){
    let _this = this
    $api.getptGoods({
      keyword:_this.data.search
    }).then((res) => {
      var list = res.data.data;

      for (var i = 0; i < list.length; i++) {
        list[i].iconState = false;
        list[i].num = 1;
        list[i].is_buy = 0;
      }
      _this.setData({
        list: list,
        loadModal: false,
        sousuoType:'search'
      })
    }).catch((err) => {
      _this.setData({
        loadModal: false
      })
    })
  },
  Readingdetails(e) {
    var _this = this;
    wx.navigateTo({
      url: '/pages/Readingdetails/Readingdetails?pt=1&id=' + e.currentTarget.dataset.id,
    })
  },
  onKey(e) {
    console.log(e)
    this.setData({
      search: e.detail.value
    })
  },
  rmsearch(e){
    this.setData({
      search: e.currentTarget.dataset.item
    })
    this.getptGoods()
  }
})